﻿namespace Repositories.RM;

/// <summary>
/// 分页请求模型
/// </summary>
public class PageQueryRM
{
    /// <summary>
    /// 分页页码
    /// </summary>
    [NumRequired(ErrorMessage = "分页页码必须大于0")]
    public int PageIndex { get; set; }
    /// <summary>
    /// 分页页容量
    /// </summary>
    private int _pageSize { get; set; }
    /// <summary>
    /// 页容量
    /// </summary>
    public int PageSize
    {
        get
        {
            if (_pageSize == 0)
            {
                _pageSize = 15;
            }
            return _pageSize;
        }
        set
        {
            _pageSize = value;
        }
    }
    /// <summary>
    /// 搜索关键字
    /// </summary>
    public string? SearchKey { get; set; }
    /// <summary>
    /// 排序字段名称
    /// </summary>
    public string? FieldName { get; set; }
    /// <summary>
    /// 是否倒序
    /// </summary>
    public bool Desc { get; set; }
}
/// <summary>
/// 数字类型必填项验证标签
/// </summary>
public class NumRequired : ValidationAttribute
{
    /// <summary>
    /// 是否有效
    /// </summary>
    /// <param name="value"></param>
    /// <returns></returns>
    public override bool IsValid(object value)
    {
        return Convert.ToInt32(value) > 0;
    }
}